package _15_generics._15_4;

import _15_generics._15_3.Fibonacci;
import _15_generics._15_3.coffee.Coffee;
import _15_generics._15_3.coffee.CoffeeGenerator;
import net.mindview.util.Generator;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 利用生成器，填充一个Collection
 */
public class _05_Generators {
    public static <T> Collection<T> fill(Collection<T> coll, Generator<T> gen,int n){
        for (int i =0; i< n;i++){
            coll.add(gen.next());
        }
        return coll;
    }

    public static void main(String[] args) {
        Collection<Coffee> coffees =
                fill(new ArrayList<>(), new CoffeeGenerator(), 5);
        System.out.println(coffees);
        Collection<Integer> fNumbers =
                fill(new ArrayList<>(), new Fibonacci(), 5);
        System.out.println(fNumbers);
    }
}
